package edu.zut.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.zut.enums.GenderEnum;
import edu.zut.mapper.ZyUserMapper;
import edu.zut.pojo.ZyUser;
import edu.zut.service.ZyUserService;
import org.apache.ibatis.type.TypeException;
import org.springframework.beans.TypeMismatchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindException;


@Service
public class ZyUserServiceImpl extends ServiceImpl<ZyUserMapper, ZyUser> implements ZyUserService {

    @Autowired
    private ZyUserMapper zyUserMapper;

//    事务注解  业务层 的方法上或类上
//    propagation 事务的传播行为   Isolation 隔离级别
//    rollbackFor 设置异常回滚 默认所有运行时异常
//    noRollbackFor : 设置不回滚异常
//    readOnly : 设置是否只读  默认 false
//    timeout  设置超时时长
//    value/transactionManager  指定使用的事务管理器   默认由数据层框架决定
    @Transactional(propagation = Propagation.REQUIRED,
            isolation = Isolation.REPEATABLE_READ,
            rollbackFor = {BindException.class},
            noRollbackFor = {TypeMismatchException.class},
            readOnly = false,timeout = 30
    )
    @Override
    public void testTransaction() {
        ZyUser user = new ZyUser();
        user.setName("阿宝");
        user.setAge(18);
        user.setEmail("7189789@qq.com");
        user.setGender(GenderEnum.MALE);
        user.insert();
        int i = 1/0;

    }
}
